package com.xiaobug.baselibrary.base;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;

import com.ljb.commlibrary.permission.DefaultPermissionSetting;
import com.ljb.commlibrary.permission.PermissionCallBack;
import com.ljb.commlibrary.permission.PermissionUtils;

import java.util.List;


/**
 * 闪屏页基类
 * Created by ljb on 2018/4/27.
 */

public abstract class BaseSplashActivity extends AppCompatActivity {
    protected final String TAG = getClass().getSimpleName();
    private String[] mPermissions;

    private void request() {
        new PermissionUtils(this)
                .setCallback(new PermissionCallBack() {
                    @Override
                    public void onPermissionSucess(List<String> permissions) {
                        onRequestPermissionsSucess(permissions);

                    }

                    @Override
                    public void onPermissionFaild(List<String> permissions) {

                    }

                    @Override
                    public void onPermissionSettingCancle(List<String> permissions) {
                        onRequestPermissionQuit(permissions);

                    }
                })
                .request(mPermissions);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == DefaultPermissionSetting.REQUESTCODE_SETTING) {
            request();
        }
    }

    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@分割线@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    /**
     * 请求权限
     *
     * @param permissions
     */
    protected void requestPermission(String... permissions) {
        mPermissions = permissions;
        request();
    }

    /**
     * 权限请求成功
     *
     * @param permissions
     */
    protected abstract void onRequestPermissionsSucess(List<String> permissions);

    /**
     * 权限请求失败
     *
     * @param permissions
     */
    protected abstract void onRequestPermissionQuit(List<String> permissions);
}
